Socket
Socket
Sign inDemoInstall

apollo-cache-inmemory

Package Overview
Dependencies
Maintainers
4
Versions
149
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-cache-inmemory

Core abstract of Caching layer for Apollo Client


Version published
Weekly downloads
420K
increased by2.41%
Maintainers
4
Weekly downloads
 
Created

What is apollo-cache-inmemory?

The `apollo-cache-inmemory` package is a core component of Apollo Client, which is used for managing and caching GraphQL data in the client-side application. It provides an in-memory cache implementation that allows for efficient data retrieval and storage, enabling features like query result caching, cache normalization, and cache persistence.

What are apollo-cache-inmemory's main functionalities?

Creating an InMemoryCache

This feature allows you to create an instance of `InMemoryCache`, which is the main cache implementation provided by the package. This cache can be used to store and retrieve GraphQL query results.

const { InMemoryCache } = require('apollo-cache-inmemory');
const cache = new InMemoryCache();

Configuring Cache Policies

This feature allows you to configure cache policies, such as merge functions, to control how data is merged into the cache. This is useful for handling pagination and other complex data structures.

const cache = new InMemoryCache({
  typePolicies: {
    Query: {
      fields: {
        myField: {
          merge(existing, incoming) {
            return { ...existing, ...incoming };
          }
        }
      }
    }
  }
});

Reading and Writing to the Cache

This feature allows you to read from and write to the cache directly using GraphQL queries. This is useful for updating the cache after performing local state updates or other client-side operations.

const { gql } = require('apollo-boost');
const query = gql`{ myField }`;
const data = cache.readQuery({ query });
cache.writeQuery({ query, data: { myField: 'newValue' } });

Cache Persistence

This feature allows you to persist the cache to a storage medium, such as localStorage, so that the cache can be restored when the application is reloaded. This helps in maintaining the state across sessions.

const { persistCache } = require('apollo-cache-persist');
persistCache({
  cache,
  storage: window.localStorage
});

Other packages similar to apollo-cache-inmemory

FAQs

Package last updated on 09 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc